//
// Created by ych on 2/14/24.
//

#ifndef MATINTERPRETER_LEXER_H
#define MATINTERPRETER_LEXER_H

#include "reader.h"

#define FIRST_REVERSED 257
typedef enum YTK_ {
    TK_TRUE = FIRST_REVERSED,
    TK_FALSE,
    TK_ELSE,
    TK_IF,
    TK_WHILE,
    TK_FUNCTION,
    TK_RETURN,
    TK_VAR,
    TK_DEL,
    TK_BREAK,
    TK_IMPORT,
    TK_NAME,
    TK_INT_V,
    TK_FLOAT_V,
    TK_STRING_V,
    TK_NOTEQUAL,
    TK_EQUAL,
    TK_GREATEREQUAL,
    TK_LESSEQUAL,
    TK_INNER,
    TK_POW,
    TK_EOF,
    TK_ILLEGAL,
    LAST_TK_,
} TK_;
typedef enum LError{
    L_CH_ERROR,
    L_ID_ERROR,
    L_NUM_ERROR,
    L_QM_ERROR,
}LError;
typedef struct YToken {
    TK_ token_type;
    union TValue {
        Int i;
        Float f;
        String *string;
    } token_value;
} Token;
void freeToken(Token* token);
typedef struct YState YState;
typedef struct YLexer {
    YState *y_state;
    Reader *reader;
} Lexer;

void initLexer(Lexer *lexer, YState *y_state);
Token getNextToken(Lexer *lexer);
void skipBlanks(Lexer *lexer);
void freeLexer(Lexer *lexer);
void lexerThrow(Lexer *lexer,size_t length,LError type);

#endif //MATINTERPRETER_LEXER_H
